package com.qiaofang.dataprocessing.service.impl;

import com.qiaofang.dataprocessing.dao.SysFieldDao;
import com.qiaofang.dataprocessing.service.SysFieldSyncService;
import com.qiaofang.dataprocessing.stub.bean.SysFieldProperty;
import com.qiaofang.dataprocessing.stub.bean.response.SysFieldSyncResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by IDEA.
 *
 * @auther Zym.
 * @company qiaofang
 * @date 2020/11/18 17:18
 */
@Service
@Slf4j
public class SysFieldSyncServiceImpl implements SysFieldSyncService {
    @Autowired
    private SysFieldDao sysFieldDao;

    @Override
    public SysFieldSyncResponse getSyncResponse(Date timing) {
        SysFieldSyncResponse response = new SysFieldSyncResponse();
        if (timing == null){
            //初始化数据
            List<SysFieldProperty> list = new LinkedList<>();
            list.add(new SysFieldProperty(-1L, "归属人1", 0 , true, true));
            list.add(new SysFieldProperty(-2L, "归属人2", 0 , true, false));
            list.add(new SysFieldProperty(-3L, "归属人3", 0 , true, false));
            list.addAll(sysFieldDao.getListForSync());
            response.setSysFieldList(list);
            response.setOpFlag(1);
        }else {
            if (sysFieldDao.getUpdateCountForSync(timing) > 0){
                if (sysFieldDao.getCountForSync() > 0){
                    response.setOpFlag(2);
                    response.setSysFieldList(sysFieldDao.getListForSync());
                }else {
                    response.setOpFlag(3);
                }
            }else {
                response.setOpFlag(4);
            }
        }
        return response;
    }
}
